home *** CD-ROM | disk | FTP | other *** search
- Listing 1 - A polymorphic hierarchy of shapes with a clone function
-
- class shape
- {
- public:
- virtual shape *clone() const = 0;
- ...
- };
-
- class circle : public shape
- {
- public:
- shape *clone() const;
- ...
- };
-
- shape *circle::clone() const
- {
- return new circle(*this);
- }
-
- class rectangle : public shape
- {
- public:
- shape *clone() const;
- ...
- };
-
- shape *rectangle::clone() const
- {
- return new rectangle(*this);
- }
-
-